package com.ymatou.iapi.godmch.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.ymatou.iapi.godmch.parameter.GetPermissionCategoryListBean;
import com.ymatou.iapi.godmch.service.GetPermissionCategoryListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*获取权限分类列表
*FreeMaker Template自动生成代码
*/
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
@TestSuite
public class Ts_GetPermissionCategoryList{
	private static GetPermissionCategoryListBean getpermissioncategorylistBean;
	private static GetPermissionCategoryListCall getpermissioncategorylistCall;
	DefGodMchWapper DefGodMchWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取权限分类列表");
	}

	@Before
	public void caseUp() {
		getpermissioncategorylistBean=new GetPermissionCategoryListBean();
		getpermissioncategorylistCall=new GetPermissionCategoryListCall();
		DefGodMchWapper=new DefGodMchWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpermissioncategorylistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPermissionCategoryList_001() {
		Logger.start(true,"获取权限分类列表,成功");
		try {
			getpermissioncategorylistCall.setData(getpermissioncategorylistBean);
			getpermissioncategorylistCall.callService();			
			Logger.verifyEquals("200", getpermissioncategorylistCall.getString("status"), "验证status");
			JsonArray ja = getpermissioncategorylistCall.getJsonObject().get("result").getAsJsonObject().get("categoryDtos").getAsJsonArray();
			for (JsonElement categoryDto : ja) {
				int categoryId=categoryDto.getAsJsonObject().get("categoryId").getAsInt();
				Map m=DefGodMchWapper.selectPermissionCategory(categoryId).get(0);
				String name=categoryDto.getAsJsonObject().get("name").getAsString();
				Logger.verifyEquals(m.get("CategoryName"), name, "验证CategoryName");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}